package com.carrot.uaa.util;

import cn.hutool.core.date.DateUnit;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

/**
 * 日期工具类
 * @author liuhongzhen
 */
public final class DateUtils {

    /**
     * 获取当天剩余时间
     * @param dateUnit 单位
     * @return
     */
    public static Long remainingTimeByDay(DateUnit dateUnit){
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();

        // 获取当天的结束时间（23:59:59）
        LocalDateTime endOfDay = currentTime.with(LocalTime.MAX);

        // 计算当前时间到当天结束的剩余时间（分钟）
        long minutesRemaining;
         switch (dateUnit){
             case MINUTE ->  minutesRemaining = ChronoUnit.MINUTES.between(currentTime, endOfDay);
             case SECOND ->  minutesRemaining = ChronoUnit.SECONDS.between(currentTime, endOfDay);
             case HOUR   ->  minutesRemaining = ChronoUnit.HOURS.between(currentTime, endOfDay);
             default -> minutesRemaining=0L;
         }

       return minutesRemaining;
    }
}
